<?php

namespace App\Services\WechatApi;

use Illuminate\Support\Facades\Http;

class WechatApiMessage extends WechatApiBase
{
    // 发送 图文链接 客服消息给玩家
    // https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/kf-mgnt/kf-message/sendCustomMessage.html
    public function sendCustomMessageToLink($access_token, $openid, $title, $description, $url, $thumb_url)
    {
        $api = "cgi-bin/message/custom/send?access_token={$access_token}";
        return $this->send2($api, json_encode([
            'touser' => $openid,
            'msgtype' => 'link',
            'link' => [
                'title' => $title,
                'description' => $description,
                'url' => $url,
                'thumb_url' => $thumb_url,
            ],
        ], JSON_UNESCAPED_UNICODE), 'post');
    }

    // 发送 文本消息 客服消息给玩家
    // https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/kf-mgnt/kf-message/sendCustomMessage.html
    public function sendCustomMessageToText($access_token, $openid, $content)
    {
        $api = "cgi-bin/message/custom/send?access_token={$access_token}";
        return $this->send2($api, json_encode([
            'touser' => $openid,
            'msgtype' => 'text',
            'text' => [
                'content' => $content,
            ],
        ], JSON_UNESCAPED_UNICODE), 'post');
    }

    // 检查一段文本是否含有违法违规内容
    // https://developers.weixin.qq.com/minigame/dev/api-backend/open-api/sec-check/security.msgSecCheck.html
    public function msgSecCheck($access_token, $openid, $scene, $content)
    {
        $api = "wxa/msg_sec_check?access_token={$access_token}";
        return $this->send($api, [
            'version' => 2,
            'openid' => $openid,
            'scene' => $scene,
            'content' => $content,
        ], 'post');
    }
}
